<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>标签栏切换效果</title>
    <style>
        body{border: 1px solid #ccc;width: 348px;height: 80px;margin: 0 auto;}
        .tab-head-div{float: left;padding-left: 39px;background: black;color: #ffffff;
          }
    </style>
</head>
<body>
    <h2>标签栏切换效果</h2>
    <div class="tab-box">
      <div class="tab-head">
        <div class="tab-head-div current">标签一</div>
        <div class="tab-head-div">标签二</div>
        <div class="tab-head-div">标签三</div>
        <div class="tab-head-div">标签四</div>
      </div>
      <div class="tab-body">
        <div class="tab-body-div current"> 1 </div>
        <div class="tab-body-div"> 2 </div>
        <div class="tab-body-div"> 3 </div>
        <div class="tab-body-div"> 4 </div>
      </div>
    </div>
    <script>
        var tabs=document.getElementsByClassName('tab-head-div');
        var divs=document.getElementsByClassName('tab-body-div');
        for(var i=0;i<tabs.length;i++){
            tabs[i].onmouseover=function(){
                for(var i=0;i<divs.length;i++){
                    if(tabs[i]==this){
                        divs[i].classList.add('current');
                        tabs[i].classList.add('current');
                    }else{
                        divs[i].classList.remove('current');
                        tabs[i].classList.remove('current');
                    }
                }
            };
        }
    </script>
    <p><a href="default.html">返回目录</a></p>
    <p><a href="第七章.html">返回第七章</a></p>
    <p><a href="列表的增删和移动.html">下一题</a></p>
    <p><a href="第八章.html">下一章</a></p>
</body>
</html>